let createNewPromise = (url,data,method,promiseResolve)=>{
	return new Promise(() => {
		wx.request({
			url:url,
			data:data,
			method:method,
			header:{
				token: getApp().globalData.token
			},
			success:(res)=>{ 
				promiseResolve(res.data.data); 
			},
			fail:(err)=>{    
			  	console.log(res);  
			},
		})
	})
}

let createNewPromise1 = (url,data,method,promiseResolve)=>{
	return new Promise(() => {
		wx.request({
			url:url,
			data:data,
			method:method,
			header:{
				token: getApp().globalData.token
			},
			success:(res)=>{ 
				promiseResolve(res.data); 
			},
			fail:(err)=>{    
			  	console.log(res);  
			},
		})
	})
}

let getResult = (url,params,method)=>{
	let promiseTemp = null;
	let promiseResolve = null;

	async function fun(){
	    promiseTemp = new Promise(resolve => promiseResolve = resolve); 
		createNewPromise(url,params,method,promiseResolve);
		let res = await promiseTemp;
		return res;
	}
	return fun()
}

let getResult1 = (url,params,method)=>{
	let promiseTemp = null;
	let promiseResolve = null;

	async function fun(){
	    promiseTemp = new Promise(resolve => promiseResolve = resolve); 
		createNewPromise1(url,params,method,promiseResolve);
		let res = await promiseTemp;
		return res;
	}
	return fun()
}
//添加评论
const addCom = (stars,courseid,content)=>{
	console.log(stars);
	console.log(courseid);
	console.log(content);
	let url = getApp().globalData.baseUrl + "course/eval/add";
	let data = {
		stars: stars,
		courseId: courseid,
		content: content
	}
	return getResult1(url,data,"POST");
}
//获取评论
const getComList = (courseId)=>{
	let url = getApp().globalData.baseUrl + "course/eval";
	let data = {
		courseId:courseId
	}
	return getResult(url,data,"GET");
}

export default{
	addCom,
	getComList
}